<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>修改型号记录</title>
	<link rel="stylesheet" type="text/css" href="/webapp/css/easyui.css">
	<link rel="stylesheet" type="text/css" href="/webapp/css/icon.css">
	<link rel="stylesheet" type="text/css" href="/webapp/css/color.css">
	<link rel="stylesheet" type="text/css" href="/webapp/css/public.css">
	<script type="text/javascript" src="/webapp/js/lib/jquery.min.js"></script>
	<script type="text/javascript" src="/webapp/js/lib/jquery.easyui.min.js"></script>
	<script type="text/javascript" src="/webapp/js/lib/jquery.global.settings.js"></script>
	<script type="text/javascript" src="/webapp/js/lib/ajaxfileupload.js"></script>
	<script type="text/javascript" src="/webapp/js/common/config.js"></script>
</head>
<body>
<div class="easyui-container-fluid">
	<div class="easyui-panel" style="border: none;">
		<div class="nav" id="nav"></div>
		<div class="easyui-panel" style="border:none;">
			<form id="ff" method="post">
				<div style="margin-bottom:20px;margin-left: 40px">
					<span style="color:red">关于禁用详情：1、型号重复：只需要填正确的型号码,品牌码和品类码可不填
						</br>&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp
						2、品牌错误：只修改品牌，新品牌码必填
						</br>&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp
						3、品类错误：只修改品类，新品类码必填
						</br>&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp
						4、其他：将相应的销售数据禁用
					</span>
				</div>
				<div style="margin-bottom:20px">
					<label class="item-label">原品类：</label>
					<select class="easyui-combobox" id="categorySelect" name="categoryCode" style="width:174px;" required="required" >
					</select>
					<label class="item-label"><span class="item-required">*</span>新品类码：</label>
					<input type="text" class="easyui-textbox " name="correctCategoryCode" id="correctCategoryCode"   />


				</div>
				<div style="margin-bottom:20px">
					<label class="item-label"><span class="item-required">*</span>原品牌码：</label>
					<input type="text" class="easyui-textbox " name="wrongBrandCode" id="wrongBrandCode" required="required"  data-options="required:true"/>
					<label class="item-label"><span class="item-required">*</span>新品牌码：</label>
					<input type="text" class="easyui-textbox " name="correctBrandCode" id="correctBrandCode"  />
				</div><div style="margin-bottom:20px">

				<label class="item-label"><span class="item-required">*</span>原型号码：</label>
				<input type="text" class="easyui-textbox " name="wrongModelCode" id="wrongModelCode"  data-options="required:true"/>
					<label class="item-label"><span class="item-required">*</span>新型号码：</label>
					<input type="text" class="easyui-textbox " name="correctModelCode" id="correctModelCode"  />
				</div>
				<div style="margin-bottom:20px">
					<label class="item-label"><span class="item-required">*</span>禁用理由：</label>&nbsp
					<label class="item-label" style='padding:0 10px;' style="font-size:80px"><input type='checkbox' name='disableDetails'class ="checkAll" value='I' style='margin-right:10px; '/>型号重复</label>
					<label class="item-label" style='padding:0 10px;'><input type='checkbox' name='disableDetails' class ="checkAll" value='II' style='margin-right:10px; '/>品牌错误</label>
					<label class="item-label" style='padding:0 10px;' ><input type='checkbox' name='disableDetails' class ="checkAll" value='III' style='margin-right:10px; '/>品类错误</label>
					<label class="item-label" style='padding:0 10px;'><input type='checkbox' name='disableDetails'class ="checkAll"  value='VI' style='margin-right:10px; '/>其他</label>

				</div>


			</form>
			<div style="margin-left: 100px;margin-bottom: 20px;">
				<a href="javascript:void(0)" class="easyui-linkbutton c8" onclick="submitForm()" style="width:80px">保存</a>
				<a href="javascript:void(0)" class="easyui-linkbutton" onclick="cancelForm()" style="width:80px">取消</a>
			</div>
		</div>

	</div>
</div>
</body>
<script type="text/javascript">
    var id = getQueryParameter("id");categoryCode=getQueryParameter("categoryCode");
    $(function(){

        setNav();
        $.when(initCategorySelect("categorySelect")).done(function(){
            initFormData();
        });
    });
    function initFormData(){
        if(id){
            $.ajax({
                url:config.url +"/modifyRecord/"+id,
                type:'get',
                data:{},
                xhrFields:{withCredentials:true},
                success:function(data){
                    //填充表单
                    if(data){
                        var item = changeProperty2String(data);
                        if(!item.values){
                            item.values = [];
                        }
                        $("#ff").form("load",item);
                    }
                },
                error:function(){
                }
            });
        }
        $("#categorySelect").combobox("select",categoryCode);
        $("#categorySelect").combobox('readonly', true);
        $('#wrongBrandCode').textbox('readonly',true);
        $('#wrongModelCode').textbox('readonly',true);
    }

    function submitForm(){
        $("#ff").form("submit",{
            onSubmit:function(){
                var valid = $(this).form('enableValidation').form('validate');
                if(valid){
                    var formData = getFormData(document.getElementById("ff"));
                    var method = "POST";
                    if(id){
                        method = "PATCH";
                        formData.id = id;
                    }
                    var disableDetails=[];
                    var users = document.getElementsByName("disableDetails"); //得到所有的checkbox
                    for(var i=0; i<users.length; i++){
                        if(users[i].checked){ //如果checkbox被选中
                            console.log(users[i].value);
                            if(users[i].value=="I" && formData.correctModelCode==""){
                                $.messager.alert("提示","请输入新型号码","error");
                                return;
                            }
                            if(users[i].value=="II" && formData.correctBrandCode==""){
                                $.messager.alert("提示","请输入新品牌码","error");
                                return;
                            }
                            if(users[i].value=="III" && formData.correctCategoryCode==""){
                                $.messager.alert("提示","请输入新品类码","error");
                                return;
                            }

                            disableDetails.push(users[i].value); //将被选中checkbox背后的值添加到数组中
                        }
                    }
                    formData.disableDetails=disableDetails;
                    $.ajax({
                        url:config.url+"/modifyRecord",
                        type:method,
                        data:JSON.stringify(formData),
                        dataType:"json",
                        contentType:"application/json;charset=UTF-8",
                        xhrFields:{withCredentials:true},
                        beforeSend:function(){
                            $.messager.progress({
                                title:"请稍等",
                                interval:50,
                                text:"操作进行中..."
                            });
                        },
                        complete:function(){
                            $.messager.progress("close");
                        },
                        success:function(data){
                            if(data.code==200){
                                $.messager.alert("提示",data.msg,"info",function () {
                                    window.parent.closeCurrentTab(true);
                                });
                            }else {
                                $.messager.alert("提示",data.msg,"error");
                            }
                        },
                        error:function(data){
                            if(data!=200){
                                $.messager.alert("提示",data.msg||"操作失败","error");
                            }
                        }
                    });
                    return false;
                }
                return false;
            }
        })
    }
    function cancelForm(){
        window.parent.closeCurrentTab();
    }

</script>
</html>